package com.achao.achaomq.controller;


import com.achao.achaomq.annotation.ApiMonitorAnnotation;
import com.achao.achaomq.entity.R;
import com.achao.achaomq.entity.UserPO;
import com.achao.achaomq.entity.UserVO;
import com.achao.achaomq.service.UserService;
import com.achao.achaomq.utils.JwtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/login")
public class UserController {

    @Autowired
    private UserService userService;

    @Autowired
    private JwtUtil jwtUtil;
    /**
     * 登录
     */
    @PostMapping
    @ApiMonitorAnnotation(apiModel = "token_model",apiCode = "login",apiName = "获取token")
    public R login(@RequestBody UserVO user){
        UserPO res = userService.userLogin(user);
        String token = jwtUtil.createToken(res);
        return R.successResult(token,"获取token");
    }

}
